import numpy as np
from numpy.linalg import eig, inv
from numpy import diag

if __name__ == '__main__':
    matrix = np.array([
        [1, 5],
        [0, 6]
    ])

    # 计算矩阵的特征值和特征向量
    eigenvalues, eigenvectors = eig(matrix)
    print("矩阵的特征值为：", eigenvalues)
    print("矩阵的特征向量为：\n", eigenvectors)

    # 构建对角线 ∧ 矩阵
    lambda_matrix = diag(eigenvalues)
    print(lambda_matrix)

    # 计算特征向量的逆矩阵
    inverse_eigenvalues = inv(eigenvectors)
    print(inverse_eigenvalues)

    # 校验矩阵和逆矩阵的积是否为单位阵
    print(eigenvectors @ inverse_eigenvalues)
    print(inverse_eigenvalues @ eigenvectors)

    # 校验释放成立
    print(eigenvectors @ lambda_matrix @ inverse_eigenvalues)
    print(inverse_eigenvalues @ matrix @ eigenvectors)



